<?php


namespace app\business\model;


use think\Model;

class Order extends Model
{
    public function updateOrderStatus(string $orderNum,int $businessId,int $deliveryStatus){
        return $this->where([
            'orderNum'      =>  $orderNum,
            'businessId'    =>  $businessId
        ])->update([
            'orderStatus'    =>  $deliveryStatus
        ]);
    }
    /**
     * @findOrderStatus 查询订单状态
     * @param $orderId
     * @return Order
     */
    public function findOrderStatus(int $orderId){
        return $this->field('orderStatus')->where('id',$orderId)->find();
    }
    /**
     * @createTime  订单创建时间
     * @param $orderId
     * @return Order
     */
    public function createTime(int $orderId){
        return $this->field('createTime')->where('id',$orderId)->find();
    }

    /**
     * @allOrders 全部订单
     * @param int $businessId
     * @return mixed
     */
    public function allOrders(int $businessId){
        //全部订单
        return $this->field('orderNum,orderStatus,createTime,orderRemarks,userPhone,provide,city,county,street,detail,realTotalMoney')
            ->where([
                'businessId'        =>  $businessId,
                'deleted'           =>  '0'
            ])->all();
    }

    /**
     * @otherOrders 其他订单
     * @param int $businessId
     * @param string $deliveryStatus
     * @return mixed
     */
    public function otherOrders(int $businessId,string $deliveryStatus){
        return $this->field('orderNum,orderStatus,createTime,orderRemarks,userPhone,provide,city,county,street,detail,realTotalMoney')
            ->where([
                'businessId'        =>  $businessId,
                'orderStatus'       =>  $deliveryStatus,
                'deleted'           =>  '0'
            ])->all();
    }
}